package com.softeem.score.manager.controller.admin;

import com.github.pagehelper.PageInfo;
import com.softeem.score.common.log.annotation.Log;
import com.softeem.score.common.log.enums.OperatorType;
import com.softeem.score.manager.service.AnnouncementService;
import com.softeem.score.model.entity.educational.Announcement;
import com.softeem.score.model.vo.common.Result;
import com.softeem.score.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhu
 * @since 2024-02-14
 * 公告控制类
 */
@Tag(name = "公告管理")
@RestController
@RequestMapping("/admin/announcement")
public class AnnouncementController {
    @Autowired
    private AnnouncementService announcementService;

    @Log(title = "发布公告",businessType = 0,operatorType = OperatorType.MANAGE)
    @Operation(summary = "发布公告")
    @PostMapping(value = "/saveAnnouncement")
    public Result saveAnnouncement(@RequestBody Announcement announcement) {
        announcementService.saveAnnouncement(announcement);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询所有公告")
    @GetMapping(value = "/findAllAnnouncement/{pageNum}/{pageSize}")
    public Result findAllAnnouncement(@PathVariable(value = "pageNum") Integer pageNum,
                                      @PathVariable(value = "pageSize") Integer pageSize) {
        PageInfo<Announcement> announcement = announcementService.findAllAnnouncement(pageSize, pageNum);
        System.out.println("announcement = " + announcement);
        return Result.build(announcement, ResultCodeEnum.SUCCESS_CODE);
    }
    @Log(title = "发布公告",businessType = 0,operatorType = OperatorType.MANAGE)
    @Operation(summary = "删除公告")
    @DeleteMapping(value = "/deleteAnnouncement/{id}")
    public Result deleteAnnouncement(@PathVariable(value = "id") Long id) {
        announcementService.deleteAnnouncement(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
}